<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";

	import {
		postTableData
	} from "@/api/table";


	import {
		searchDataZzgz
	} from "@/api/search";
	import {
		addOrUpdateZzgz
	} from "@/api/addOrUpdate";

	const city = window.globalObj.name;


	const editorRef = shallowRef();
	const editorRef1 = shallowRef();

	const toolbarConfig = {};
	const toolbarConfig1 = {};
	const editorConfig = {
		placeholder: "请输入内容..."
	};
	const mode = ref("default");
	const mode1 = ref("default");

	// 加载html
	const initHtml = () => {
		searchDataZzgz({
			m: "能力现状-建设现状"
		}).then((res) => {
			const {
				data
			} = res
			valueHtml.value = data.find((x) => x.k === "党组织建设现状")?.v || "";
			valueHtml1.value = data.find((x) => x.k === "心理防护专业队建设现状")?.v || "";
		})
	};

	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};
	const handleCreated1 = (editor) => {
		editorRef1.value = editor; // 记录 editor 实例，重要！
	};

	const valueHtml = ref(
		"党组织建设现状：共编配XX个党委、XX个党工委、XX个党支部、XX个党总支。具体情况如下："
	);
	const valueHtml1 = ref(
		"党组织建设现状：共编配XX个党委、XX个党工委、XX个党支部、XX个党总支。具体情况如下："
	);

	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateZzgz({
					m: "能力现状-建设现状",
					data: [{
						k: "党组织建设现状",
						v: valueHtml.value,
					},
					{
						k: "心理防护专业队建设现状",
						v: valueHtml1.value,
					}],
				})
				.then((result) => {
					if (result.code === 200) {
						ElMessage.success("操作成功");
						initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	}


	onBeforeUnmount(() => {
		const editor = editorRef.value;
		const editor1 = editorRef1.value;
		if (!editor) return;
		if (!editor1) return;
		editor.destroy();
		editor1.destroy();

	});


	// 表头单元格样式
	const headerCellStyle = () => {
		return {
			backgroundColor: "#f5f7fa",
			color: "rgba(0,0,0,0.85)",
			fontSize: "14px",
			height: "54px",
		};
	};
	// 单元格样式
	const cellStyle = () => {
		return {
			color: "rgba(0,0,0,0.65)",
			fontSize: "14px",
			lineHeight: "22px",
		};
	};

	const tableData1 = ref([])
	const tableData2 = ref([])
	const getList1 = () => {
		return postTableData({
			docType: "politicalwork",
			method: "dangzuzhijiansheqingkuang",
		}).then(result => {
			if (result.code === 200) {
				tableData1.value = result?.data || []
			}
		})
	}
	const getList2 = () => {
		return postTableData({
			docType: "politicalwork",
			method: "xinlifanghuzhuanyejianshe",
		}).then(result => {
			if (result.code === 200) {
				tableData2.value = result?.data || []
			}
		})
	}

	onMounted(async () => {
		await initHtml();
		await getList1()
		await getList2()
	});
</script>
<template>
	<div>
		<FirstTitle name="党组织建设现状" class="top-15" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>
		<div class="top-15  text-center">{{ city }}党组织建设情况统计表（单位:个）</div>
		<el-table id="table" :data="tableData1" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="60" align="center" />
			<el-table-column prop="region_name" label="行政区域" />
			<el-table-column prop="org_type" label="组织类型" />
			<el-table-column prop="org_num" label="党组织数量" />
		</el-table>

		<!-- 	<FirstTitle name="干部队伍建设现状" class="top-15" />
		<div class="top-15">
			共有干部XX人，其中：市本级干部XX人、区（县）本级干部XX人、街道干部XX人、社区干部XX人。具体情况如下：
		</div>
		<div class="top-15  text-center">{{ city }}干部队伍建设情况统计表（单位:人）</div>
		<el-table id="table" :data="tableData" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="c1" label="序号" width="60" align="center" />
			<el-table-column prop="c2" label="行政区划" />
			<el-table-column prop="c3" label="市本级" />
			<el-table-column prop="c3" label="区本级" />
			<el-table-column prop="c3" label="街道干部人数" />
			<el-table-column prop="c3" label="社区干部人数" />
		</el-table>


		<FirstTitle name="政治工作机构（干部）建设现状" class="top-15" />
		<div class="top-15">
			共有XX个党工委、XX个街道党政办公室、XX个社区书记、XX个社区副书记。
		</div>
		<div class="top-15  text-center">{{ city }}政治工作机构（干部）建设情况统计表（单位:个）</div>
		<el-table id="table" :data="tableData" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="c1" label="序号" width="60" align="center" />
			<el-table-column prop="c2" label="行政区划" />
			<el-table-column prop="c3" label="党委数量" />
			<el-table-column prop="c3" label="党工委数量" />
			<el-table-column prop="c3" label="党支部数量" />
			<el-table-column prop="c3" label="党总支数量" />
			<el-table-column prop="c3" label="街道党政办公室数量" />
			<el-table-column prop="c3" label="社区书记数量" />
			<el-table-column prop="c3" label="社区副书记数量" />
		</el-table> -->


		<FirstTitle name="心理防护专业队建设现状" class="top-15" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef1" :defaultConfig="toolbarConfig1"
				:mode="mode1" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml1" :defaultConfig="editorConfig"
				:mode="mode1" @onCreated="handleCreated1" />
		</div>
		<div class="top-15  text-center">{{ city }}心理防护专业队建设情况统计表</div>
		<el-table id="table" :data="tableData2" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="60" align="center" />
			<el-table-column prop="jd_name" label="行政区划" />
			<el-table-column prop="zyd_num" label="专业队数量" />
			<el-table-column prop="p_num" label="人员数量" />
		</el-table>





		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>